package com.carmeth.sudoqu;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SelectNumber extends Activity implements OnClickListener {
	
	private final String CLASS=this.getClass().getSimpleName();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.select_num);
		Log.v(CLASS, "Creado");
		findViewById(R.id.num1).setOnClickListener(this);
		findViewById(R.id.num2).setOnClickListener(this);
		findViewById(R.id.num3).setOnClickListener(this);
		findViewById(R.id.num4).setOnClickListener(this);
		findViewById(R.id.num5).setOnClickListener(this);
		findViewById(R.id.num6).setOnClickListener(this);
		findViewById(R.id.num7).setOnClickListener(this);
		findViewById(R.id.num8).setOnClickListener(this);
		findViewById(R.id.num9).setOnClickListener(this);
		
	}
	
	@Override
	public void onClick(View v) {
		int b = (Integer)getIntent().getExtras().get("button");
		Intent i = new Intent(getApplicationContext(), PuzzleGridView.class);
		Log.v(CLASS, "Button id: "+b);
		Button btn;
		switch (v.getId()) {
		case R.id.num1:
			btn = (Button) findViewById(R.id.num1);
			Log.v(CLASS, "Number Select: "+btn.getText());
			i.putExtra("button", b);
			i.putExtra("value",btn.getText());
			setResult(RESULT_OK,i);
			finish();
			break;
		case R.id.num2:
			btn = (Button) findViewById(R.id.num2);
			Log.v(CLASS, "Number Select: "+btn.getText());
			i.putExtra("button", b);
			i.putExtra("value",btn.getText());
			setResult(RESULT_OK,i);
			finish();
			break;
		case R.id.num3:
			btn = (Button) findViewById(R.id.num3);
			Log.v(CLASS, "Number Select: "+btn.getText());
			i.putExtra("button", b);
			i.putExtra("value",btn.getText());
			setResult(RESULT_OK,i);
			finish();
			break;
		case R.id.num4:
			btn = (Button) findViewById(R.id.num4);
			Log.v(CLASS, "Number Select: "+btn.getText());
			i.putExtra("button", b);
			i.putExtra("value",btn.getText());
			setResult(RESULT_OK,i);
			finish();
			break;
		case R.id.num5:
			btn = (Button) findViewById(R.id.num5);
			Log.v(CLASS, "Number Select: "+btn.getText());
			i.putExtra("button", b);
			i.putExtra("value",btn.getText());
			setResult(RESULT_OK,i);
			finish();
			break;
		case R.id.num6:
			btn = (Button) findViewById(R.id.num6);
			Log.v(CLASS, "Number Select: "+btn.getText());
			i.putExtra("button", b);
			i.putExtra("value",btn.getText());
			setResult(RESULT_OK,i);
			finish();
			break;
		case R.id.num7:
			btn = (Button) findViewById(R.id.num7);
			Log.v(CLASS, "Number Select: "+btn.getText());
			i.putExtra("button", b);
			i.putExtra("value",btn.getText());
			setResult(RESULT_OK,i);
			finish();
			break;
		case R.id.num8:
			btn = (Button) findViewById(R.id.num8);
			Log.v(CLASS, "Number Select: "+btn.getText());
			i.putExtra("button", b);
			i.putExtra("value",btn.getText());
			setResult(RESULT_OK,i);
			finish();
			break;
		case R.id.num9:
			btn = (Button) findViewById(R.id.num9);
			Log.v(CLASS, "Number Select: "+btn.getText());
			i.putExtra("button", b);
			i.putExtra("value",btn.getText());
			setResult(RESULT_OK,i);
			finish();
			break;
			
		}
	   
	}

}
